package com.shopping.dao.Impl;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.springframework.core.annotation.Order;

import com.shopping.model.Orders;


public interface OrdersDao {

	@Select("<script>select * from orders <where>"
			+"<if test='status>0'> and status=#{status}</if>"
			+ "</where> limit #{start}, #{size}</script>")
	List<Orders> orderList(@Param("status") byte status, @Param("start") int start, @Param("size") int size);

	@Select("<script>select count(*) from orders <where><if test='status>0'> and status=status</if></where></script>")
	long getCountsByStatus(@Param("status") byte status);

	@Update("update orders set status = #{status} where id = #{id}")
	void orderUpdate(@Param("id") int id, @Param("status") byte status);

	@Delete("delete from orders where id = #{id}")
	void orderDelete(int id);

	//新增订单。
	@Insert("insert into orders (total,amount,status,paytype,name,phone,address,systime,user_id) "
			+ "values (#{total},#{amount},#{status},#{paytype},#{name},#{phone},#{address},now(),#{userId})")
	@SelectKey(keyProperty="id",statement="SELECT LAST_INSERT_ID()", before=false, resultType=Integer.class)  
	void insert(Orders order);

	//查询指定id的订单，用于更新页面展示。
    @Select("select * from orders where id=#{id}")
    public Orders select(int id);
    
    //修改订单
  	@Update("update orders set status=#{status},paytype=#{paytype},name=#{name},phone=#{phone},address=#{address} where id=#{id}")
  	public boolean update(Orders order);

  	
  	//分页查询我的的订单
  	@Select("select * from orders where user_id = #{userId} limit #{start}, #{size}")
	List<Orders> orderListByUserId(@Param("userId") int userId,  @Param("start") int start, @Param("size") int size);

  	//查询我的的订单的数量
  	@Select("select count(*) from orders where user_id = #{userId}")
	long getCountsByUserId(@Param("userId") int userId);
  	
  	@Select("select * from orders")
  	List<Orders> findAllOrder();
  	

}
